<template>
  <div class="app-container">
    <el-form
      class="dialog-form"
      :rules="rules"
      ref="dataForm"
      :model="temp"
      label-position="left"
      label-width="120px"
    >
      <el-form-item label="旧密码" prop="pwd">
        <el-input v-model="temp.pwd" show-password placeholder="旧密码" style="width:300px;"></el-input>
      </el-form-item>
      <el-form-item label="新密码" prop="newPwd">
        <el-input v-model="temp.newPwd" show-password placeholder="新密码" style="width:300px;"></el-input>
      </el-form-item>
      <el-form-item label="确认密码" prop="confirmPwd">
        <el-input v-model="temp.confirmPwd" show-password placeholder="确认密码"  style="width:300px;"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" @click="dialogFormVisible = false">取消</el-button>
      <el-button type="primary" size="mini" :loading="submiting" @click="submitFormAction">确定</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      temp: {
        pwd: "",
        newPwd: "",
      },
      rules: {
        pwd: [
          {
            required: true,
            message: "请输入旧密码",
            trigger: "change",
            max: 50
          }
        ],
        newPwd: [
          { required: true, message: "请输入新密码", trigger: "change" }
        ],
        confirmPwd: [
          { required: true, message: "请输入确认密码", trigger: "change" }
        ]
      }
    };
  },
  methods: {
    submitFormAction() {
        if(this.temp.newPwd !== this.temp.confirmPwd){
            this.$message({
                message: '新密码不一致',
                type: 'warning'
            });
            return;
        }
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          this.submiting = true;
        //   const postData = Object.assign({}, this.temp);
          let url = "/admin/manager/edit_pwd";
        //   if (this.isEditing) {
        //     url = "/admin/manager/modify";
        //   }
          this.$post(url, this.temp)
            .then(data => {
              this.$$notify("修改成功");
              this.dialogFormVisible = false;
              this.temp = {};
            })
            .finally(err => {
              this.temp = {};
              console.log(err);
              this.submiting = false;
            });
        }
      });
    }
  }
};
</script>
<style>
.el-table td,
.el-table th {
  padding: 1px 0;
}
.el-table {
  font-size: 12px;
}
.opencolor {
  color: red;
}
.openSearch {
  margin-bottom: 10px;
  padding-bottom: 5px;
}
</style>